package cn.edu.lzu.dao;

import cn.edu.lzu.entity.Unit;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface UnitMapper {

    //单位数量
    @Select("select count(*) from unit where is_deleted=0")
    int selUnitCount();

    @Select("select * from unit where is_deleted=0 limit #{startIndex}, #{pageSize}")
    List<Unit> selPageUnit(int startIndex, int pageSize);

    @Select("select max(unit_id) from unit")
    Object selMaxUnitId();

    @Select("select * from unit where unit_id = #{unitId} and is_deleted=0")
    Unit selUnitById(long unitId);

    @Insert("insert into unit values(#{unitId}, #{unitName}, #{grade}, #{address}, #{telephone}, #{email}, #{picture}, #{principal}, #{officalWeb}, #{description}, #{disabled}, #{registeTime}, #{updateTime}, #{cityId}, #{type}, 0)")
    int insUnit(Unit unit);

    @Update("update unit set disabled=#{disabled} where unit_id=#{unitId}")
    int updDisabled(@Param("disabled") boolean disabled, @Param("unitId") long unitId);

    @Update("update unit set is_deleted=1 where unit_id=#{unitId}")
    int delUnitById(long unitId);

    @Update("update unit set is_deleted=1 where unit_id in (${unitIds})")
    int delBatchUnitsByIds(String unitIds);

    @Update("update unit set disabled=0 where unit_id in (${unitIds})")
    int updBatchDisabledUnitsByIds(String unitIds);

    @Update("update unit set disabled=1 where unit_id in (${unitIds})")
    int updBatchEnabledUnitsByIds(String unitIds);

    @Select("select * from unit where unit_name=#{unitName} and is_deleted=0")
    List<Unit> selUnitByName(String unitName);

    @Select("select * from unit where is_deleted=0 and city_id in (${cityIds})")
    List<Unit> selUnitsByCityId(String cityIds);
}
